<template>
  <div
    class="customer-second"
    v-loading="loading"
    element-loading-text="加载中..."
  >
    <el-form :model="ruleForm" :rules="rules" ref="ruleFormRef">
      <el-form-item prop="un_opp_flw_days">
        <el-switch
          v-model="ruleForm.un_opp_flw_status"
          :active-value="1"
          :inactive-value="0"
          inline-prompt
        />
        <span> 未建立商机客户： </span>
        <el-input style="width: 100px" v-model="ruleForm.un_opp_flw_days" />
        <span> 天未跟进，则自动流出，回到客户公海。 </span>
      </el-form-item>
      <!--  -->
      <el-form-item prop="un_opp_bld_days">
        <el-switch
          v-model="ruleForm.un_opp_bld_status"
          :active-value="1"
          :inactive-value="0"
          inline-prompt
        />
        <span> 未建立商机客户： </span>
        <el-input style="width: 100px" v-model="ruleForm.un_opp_bld_days" />
        <span> 天未建立商机，自动流出，回到客户公海。 </span>
      </el-form-item>
      <!--  -->
      <el-form-item prop="opp_cst_days">
        <el-switch
          v-model="ruleForm.opp_cst_status"
          :active-value="1"
          :inactive-value="0"
          inline-prompt
        />
        <span> 商机客户： </span>
        <el-input style="width: 100px" v-model="ruleForm.opp_cst_days" />
        <span> 天未成交，回到客户公海。 </span>
      </el-form-item>
      <!--  -->
      <el-form-item prop="cst_days">
        <el-switch
          v-model="ruleForm.cst_status"
          :active-value="1"
          :inactive-value="0"
          inline-prompt
        />
        <span> 成交客户： </span>
        <el-input style="width: 100px" v-model="ruleForm.cst_days" />
        <span> 天未跟进，则自动流出，回到客户公海。 </span>
      </el-form-item>
      <div>
        <el-button type="primary" @click="submit"> 提交 </el-button>
      </div>
    </el-form>
  </div>
</template>
<script setup>
import { listApi, addApi } from "@/plugins/api/customer/setup/second";
let ruleForm = ref({});
let rules = {
  un_opp_flw_days: [{ required: true, message: "", trigger: "change" }],
  un_opp_bld_days: [{ required: true, message: "", trigger: "change" }],
  opp_cst_days: [{ required: true, message: "", trigger: "change" }],
  cst_days: [{ required: true, message: "", trigger: "change" }],
};
let ruleFormRef = ref(null);
function submit() {
  if (!ruleFormRef.value) return;
  ruleFormRef.value.validate((valid, fields) => {
    if (valid) {
      addApi(ruleForm.value).then(() => {
        ElMessage.success("设置成功！");
        getData();
      });
    }
  });
}
let loading = ref(false);
function getData() {
  loading.value = true;
  listApi()
    .then((data) => {
      ruleForm.value = Object.assign({}, data);
      loading.value = false;
    })
    .catch(() => {
      loading.value = false;
    });
}
onMounted(() => {
  getData();
});
</script>
<style scoped lang="scss">
.customer-second {
  width: 100%;
  height: 100%;
  span {
    margin-left: 10px;
  }
}
</style>
